import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class TestPasswordHash {
    public static void main(String[] args) {
        PasswordEncoder encoder = new BCryptPasswordEncoder();
        String rawPassword = "admin123";
        String hashedPassword = encoder.encode(rawPassword);
        
        System.out.println("原密码: " + rawPassword);
        System.out.println("生成的哈希: " + hashedPassword);
        
        // 验证哈希是否匹配
        boolean matches = encoder.matches(rawPassword, hashedPassword);
        System.out.println("验证结果: " + matches);
        
        // 验证当前数据库中的哈希
        String dbHash = "$2a$10$NPEtTYQ78Df.9hNQeY.f0eJd9Q73D1yFy4Gz0yX4Vv1z4K2kZ0w7W";
        boolean dbMatches = encoder.matches(rawPassword, dbHash);
        System.out.println("数据库哈希匹配: " + dbMatches);
    }
}